home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / m17n / th-kesmanee.mim < prev    next >
Text File  |  2009-04-29  |  9KB  |  453 lines

  1. ;; th-kesmanee.mim -- Thai input method with Kesmanee keyboard layout
  2. ;; Copyright (C) 2003, 2004, 2005, 2006, 2007
  3. ;;   National Institute of Advanced Industrial Science and Technology (AIST)
  4. ;;   Registration Number H15PRO112
  5.  
  6. ;; This file is part of the m17n database; a sub-part of the m17n
  7. ;; library.
  8.  
  9. ;; The m17n library is free software; you can redistribute it and/or
  10. ;; modify it under the terms of the GNU Lesser General Public License
  11. ;; as published by the Free Software Foundation; either version 2.1 of
  12. ;; the License, or (at your option) any later version.
  13.  
  14. ;; The m17n library is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; Lesser General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU Lesser General Public
  20. ;; License along with the m17n library; if not, write to the Free
  21. ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. ;; Boston, MA 02110-1301, USA.
  23.  
  24. (input-method th kesmanee)
  25.  
  26. (description "Thai input method simulating the Kesmanee keyboard
  27. with WTT 2.0 input sequence correction.
  28. The correction algorithm follows the one shown in the following 
  29.   <http://linux.thai.net/~thep/th-xim/>
  30. ")
  31.  
  32. (title "α╕ù")
  33.  
  34. (variable
  35.  (level (_"Acceptance level
  36. The level of character sequence acceptance defined in WTT 2.0.
  37. 0 accepts any key sequence.  2 accepts only orthographic ones.
  38. 1 is somewhere between.")
  39.     1 0 1 2))
  40.  
  41. (macro
  42.  
  43.  ;; input global variables : arg1, arg2
  44.  ;; output global variable : ret
  45.  (cp
  46.   (cond
  47.    ((= level 0)
  48.     (set ret 1))
  49.    (1
  50.     (cp12))))
  51.  
  52.  ;; input global variables : arg1, arg2
  53.  ;; output global variable : ret
  54.  (ac
  55.   (cond
  56.    ((= level 0)
  57.     (set ret 1))
  58.    ((= level 1)
  59.     (ac1))
  60.    (1
  61.     (ac2))))
  62.  
  63.  ;; Level 1 & 2 composability
  64.  (cp12
  65.   (set ret 0)
  66.   (cond
  67.  
  68.    ;; next = BV1|BV2|BD|AD3|AV1|AV2|AV3, previous = CONS
  69.    ((| (= arg2 0x0E31)
  70.        (& (>= arg2 0x0E34) (<= arg2 0x0E3A))
  71.        (= arg2 0x0E4E))
  72.     (cond
  73.      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
  74.      (= arg1 0x0E25)
  75.      (& (>= arg1 0x0E27) (<= arg1 0x0E2E)))
  76.       (set ret 1))))
  77.  
  78.    ;; next = TONE, previous = CONS|BV1|BV2|AV1|AV2|AV3
  79.    ((& (>= arg2 0x0E48) (<= arg2 0x0E4B))
  80.     (cond
  81.      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
  82.      (= arg1 0x0E25)
  83.      (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
  84.      (= arg1 0x0E31)
  85.      (& (>= arg1 0x0E34) (<= arg1 0x0E39)))
  86.       (set ret 1))))
  87.  
  88.    ;; next = AD1, previous = CONS|BV1|AV1
  89.    ((& (>= arg2 0x0E4C) (<= arg2 0x0E4D))
  90.     (cond
  91.      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
  92.      (= arg1 0x0E25)
  93.      (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
  94.      (= arg1 0x0E38)
  95.      (= arg1 0x0E34))
  96.       (set ret 1))))
  97.  
  98.    ;; next = AD2, previous = TONE| AV3
  99.    ((= arg2 0x0E47)
  100.     (cond
  101.      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
  102.      (= arg1 0x0E25)
  103.      (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
  104.      (= arg1 0x0E35)
  105.      (= arg1 0x0E37))
  106.       (set ret 1))))))
  107.  
  108.  ;; Level 1 acceptance
  109.  (ac1
  110.   (set ret 1)
  111.   (cond
  112.    ((| (= arg2 0x0E31)
  113.        (& (>= arg2 0x0E34) (<= arg2 0x0E3A))
  114.        (& (>= arg2 0x0E47) (<= arg2 0x0E4E)))
  115.     (set ret 0))))
  116.  
  117.  ;; Level 2 acceptance
  118.  (ac2
  119.   (set ret 0)
  120.   (cond
  121.  
  122.    ;; next = CTRL|CONS, previous = *
  123.    ((| (<= arg2 0x001F)
  124.        (& (>= arg2 0x0080) (<= arg2 0x009F))
  125.        (& (>= arg2 0x0E01) (<= arg2 0x0E23))
  126.        (= arg2 0x0E25)
  127.        (& (>= arg2 0x0E27) (<= arg2 0x0E2E)))
  128.     (set ret 1))
  129.  
  130.    ;; next = NON|LV, previous = ~LV, 
  131.    ((| (& (>= arg2 0x0020) (<= arg2 0x007E))
  132.        (& (>= arg2 0x00A0) (<= arg2 0x0E00))
  133.        (= arg2 0x0E2F)
  134.        (& (>= arg2 0x0E3F) (<= arg2 0x0E44))
  135.        (= arg2 0x0E46)
  136.        (> arg2 0x0E4E))
  137.     (cond
  138.      ((| (< arg1 0x0E40) (> arg1 0x0E44))
  139.       (set ret 1))))
  140.  
  141.    ;; next = FV1, previous = CONS|FV1|FV2|BV1|TONE
  142.    ((| (= arg2 0x0E30) (= arg2 0x0E32) (= arg2 0x0E33))
  143.     (cond
  144.      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
  145.      (= arg1 0x0E25)
  146.      (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
  147.      (= arg1 0x0E30)
  148.      (= arg1 0x0E32)
  149.      (= arg1 0x0E33)
  150.      (= arg1 0x0E45)
  151.      (= arg1 0x0E38)
  152.      (& (>= arg1 0x0E48) (<= arg1 0x0E4B)))
  153.       (set ret 1))))
  154.    
  155.    ;; next = FV2, previous = FV3|TONE
  156.    ((= arg2 0x0E45)
  157.     (cond
  158.      ((| (= arg1 0x0E24)
  159.      (= arg1 0x0E26)
  160.      (& (>= arg1 0x0E48) (<= arg1 0x0E4B)))
  161.       (set ret 1))))
  162.  
  163.    ;; next = FV3, previous = ~LV~FV3
  164.    ((| (= arg2 0x0E24) (= arg2 0x0E26))
  165.     (cond
  166.      ((& (| (< arg1 0x0E40) (> arg1 0x0E44))
  167.      (! (= arg1 0x0E24))
  168.      (! (= arg1 0x0E26)))
  169.       (set ret 1)))))))   
  170.  
  171. (map
  172.  (map
  173.   ("!" "+")
  174.   ("\"" ".")
  175.   ("#" "α╣Æ")
  176.   ("$" "α╣ô")
  177.   ("%" "α╣ö")
  178.   ("&" "α╕┐")
  179.   ("'" "α╕ç")
  180.   ("(" "α╣û")
  181.   (")" "α╣ù")
  182.   ("*" "α╣ò")
  183.   ("+" "α╣Ö")
  184.   ("," "α╕í")
  185.   ("-" "α╕é")
  186.   ("." "α╣â")
  187.   ("/" "α╕¥")
  188.   ("0" "α╕ê")
  189.   ("1" "α╣à")
  190.   ("2" "/")
  191.   ("3" "-")
  192.   ("4" "α╕á")
  193.   ("5" "α╕û")
  194.   ("6" "α╕╕")
  195.   ("7" "α╕╢")
  196.   ("8" "α╕ä")
  197.   ("9" "α╕ò")
  198.   (":" "α╕ï")
  199.   (";" "α╕º")
  200.   ("<" "α╕Æ")
  201.   ("=" "α╕è")
  202.   (">" "α╕¼")
  203.   ("?" "α╕ª")
  204.   ("@" "α╣æ")
  205.   ("A" "α╕ñ")
  206.   ("B" "α╕║")
  207.   ("C" "α╕ë")
  208.   ("D" "α╕Å")
  209.   ("E" "α╕Ä")
  210.   ("F" "α╣é")
  211.   ("G" "α╕î")
  212.   ("H" "α╣ç")
  213.   ("I" "α╕ô")
  214.   ("J" "α╣ï")
  215.   ("K" "α╕⌐")
  216.   ("L" "α╕¿")
  217.   ("M" "?")
  218.   ("N" "α╣î")
  219.   ("O" "α╕»")
  220.   ("P" "α╕ì")
  221.   ("Q" "α╣É")
  222.   ("R" "α╕æ")
  223.   ("S" "α╕å")
  224.   ("T" "α╕ÿ")
  225.   ("U" "α╣è")
  226.   ("V" "α╕«")
  227.   ("W" "\"")
  228.   ("X" ")")
  229.   ("Y" "α╣ì")
  230.   ("Z" "(")
  231.   ("[" "α╕Ü")
  232.   ("\\" "α╕â")
  233.   ("]" "α╕Ñ")
  234.   ("^" "α╕╣")
  235.   ("_" "α╣ÿ")
  236.   ("`" "_")
  237.   ("a" "α╕ƒ")
  238.   ("b" "α╕┤")
  239.   ("c" "α╣ü")
  240.   ("d" "α╕ü")
  241.   ("e" "α╕│")
  242.   ("f" "α╕ö")
  243.   ("g" "α╣Ç")
  244.   ("h" "α╣ë")
  245.   ("i" "α╕ú")
  246.   ("j" "α╣ê")
  247.   ("k" "α╕▓")
  248.   ("l" "α╕¬")
  249.   ("m" "α╕ù")
  250.   ("n" "α╕╖")
  251.   ("o" "α╕Ö")
  252.   ("p" "α╕ó")
  253.   ("q" "α╣å")
  254.   ("r" "α╕₧")
  255.   ("s" "α╕½")
  256.   ("t" "α╕░")
  257.   ("u" "α╕╡")
  258.   ("v" "α╕¡")
  259.   ("w" "α╣ä")
  260.   ("x" "α╕¢")
  261.   ("y" "α╕▒")
  262.   ("z" "α╕£")
  263.   ("{" "α╕É")
  264.   ("|" "α╕à")
  265.   ("}" ",")
  266.   ("~" "%")))
  267.  
  268. ;; CTRL : 0000..0020, 007F..009F
  269. ;; NON  : 0021..007E, 00A0..0E00
  270. ;; CONS : 0E01..0E23, 0E25, 0E27..0E2E
  271. ;; LV   : 0E40..0E44
  272. ;; FV1  : 0E30, 0E32, 0E33
  273. ;; FV2  : 0E45
  274. ;; FV3  : 0E24, 0E26
  275. ;; BV1  : 0E38
  276. ;; BV2  : 0E39
  277. ;; BD   : 0E3A
  278. ;; TONE : 0E48..0E4B
  279. ;; AD1  : 0E4C, 0E4D
  280. ;; AD2  : 0E47
  281. ;; AD3  :
  282. ;; AV1  : 0E34
  283. ;; AV2  : 0E31, 0E36
  284. ;; AV3  : 0E35, 0E37
  285.  
  286. (state
  287.  
  288.  (init
  289.   (map
  290.    (delete @<)
  291.    (pushback 1)
  292.    (shift main)))
  293.  
  294.  (main
  295.   (map
  296.    (set x @-3)
  297.    (set y @-2)
  298.    (set z @-1)
  299.  
  300.    (set arg1 y)
  301.    (set arg2 z)
  302.    (cp)
  303.    (cond
  304.     ((= ret 1)) ;; CP(y,z) succeeded.
  305.     (1
  306.      (ac)
  307.      (cond
  308.       ((= ret 1)) ;; AC(y,z) succeeded.
  309.       (1
  310.        ;; WTT-based input sequence correction starts here.
  311.  
  312.        ;; begin
  313.        ;; if CP(x,z) then
  314.        (set arg1 x)
  315.        (set arg2 z)
  316.        (cp)
  317.        (cond
  318.     ((= ret 1)
  319.  
  320.      ;; if CP(z,y) then
  321.      (set arg1 z)
  322.      (set arg2 y)
  323.      (cp)
  324.      (cond
  325.       ((= ret 1)
  326.  
  327.        ;; reorder(y -> zy)
  328.        (delete @-2)
  329.        (insert z)
  330.        (insert y))
  331.  
  332.       ;; elif CP(x,y) then
  333.       (1
  334.        (set arg1 x)
  335.        (set arg2 y)
  336.        (cp)
  337.        (cond
  338.         ((= ret 1)
  339.  
  340.          ;; replace(y -> z)
  341.          (delete @-2)
  342.          (insert z))
  343.  
  344.         ;; elif y is FV1 and z is TONE then
  345.         ((& (| (= y 0x0E30) (= y 0x0E32) (= y 0x0E33))
  346.         (>= z 0x0E48)
  347.         (<= z 0x0E4B))
  348.  
  349.          ;; reorder(y -> zy)
  350.          (delete @-2)
  351.          (insert z)
  352.          (insert y))
  353.  
  354.         ;; else
  355.         ;; reject(z)
  356.         (1
  357.          (delete @-1))
  358.  
  359.         ;;endif
  360.         ))))
  361.  
  362.     ;; elif AC(x,z) then
  363.     (1
  364.      (set arg1 x)
  365.      (set arg2 z)
  366.      (ac)
  367.      (cond
  368.       ((& (= ret 1)
  369.           ;; Only Thai characters should be replaced.
  370.           (& (>= y 0x0E01) (<= y 0x0E5B))
  371.           (& (>= z 0x0E01) (<= z 0x0E5B)))
  372.  
  373.        ;; replace(y -> z)
  374.        (delete @-2)
  375.        (insert z))
  376.  
  377.       ;; else
  378.       ;; reject(z)
  379.       (1
  380.        (delete @-1))
  381.  
  382.       ;; endif
  383.       )))
  384.        ;; end
  385.  
  386.        ))))
  387.  
  388.    ;; Now we commit the preedit chars that are fixed.
  389.    (set w @-1)
  390.    (cond
  391.     ;; If surrounding text is supported, commit the only char in preedit.
  392.     ((> @-0 -2)
  393.      (commit))
  394.  
  395.     ;; If the last char is CTRL or NON, we can commit everything.
  396.     ((| (& (>= w 0x0000) (<= w 0x0E00))
  397.     (= w 0x0E2F)
  398.     (= w 0x0E3F)
  399.     (= w 0x0E46)
  400.     (>= w 0x0E4F))
  401.      (commit))
  402.  
  403.     ;; If the last char is CONS, we can commit everything but the last
  404.     ;; unless the second last is FV3.
  405.     ((| (& (>= w 0x0E01) (<= w 0x0E23))
  406.     (= w 0x0E25)
  407.     (& (>= w 0x0E27) (<= w 0x0E2E)))
  408.      (cond
  409.       ((| (= @-2 0x0E24) (= @-2 0x0E26))
  410.        ; not commit yet
  411.        )
  412.       (1
  413.        (delete @-1)
  414.        (commit)
  415.        (insert w))))
  416.  
  417.     ;; If the last char is LV, FV2 or FV3, we can commit
  418.     ;; everything but the last.
  419.     ((| (& (>= w 0x0E40) (<= w 0x0E45))
  420.     (= w 0x0E24)
  421.     (= w 0x0E26))
  422.      (delete @-1)
  423.      (commit)
  424.      (insert w))
  425.  
  426.     ;; If the last char is FV1 (excluding AM) and ...
  427.     ((| (= w 0x0E30) (= w 0x0E32))
  428.      (delete @-1)
  429.      (set v @-1)
  430.      (cond
  431.  
  432.       ;; ... the before last is CONS, we can commit other than the
  433.       ;; last two.
  434.       ((| (& (>= v 0x0E01) (<= v 0x0E23))
  435.       (= v 0x0E25)
  436.       (& (>= v 0x0E27) (<= v 0x0E2E)))
  437.        (delete @-1)
  438.        (commit)
  439.        (insert v)
  440.        (insert w))
  441.  
  442.       ;; ... else if the before last is not CONS, we can commit
  443.       ;; everything but the last.
  444.       (1
  445.        (commit)
  446.        (insert w))))
  447.     ))))
  448.  
  449. ;; Local Variables:
  450. ;; coding: utf-8
  451. ;; mode: emacs-lisp
  452. ;; End:
  453.